home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac 1
/
Ian and Stuart's One (Australia).iso
/
Australasian Legends
/
Commercial
/
Rainbow Hill
/
MacDOS™ 2.0.0
/
batches
/
uniqueTempName.bat
< prev
next >
Wrap
DOS Batch File
|
1994-06-19
|
2KB
|
55 lines
@echo off
! uniqueTempName.bat Returns a unique temporary file name
!
! uniqueTempName varName [path]
!
! where 'varName' is a string containing the name of the global variable into
! which the unique file name is to be returned. 'path' identifies the folder where
! the file name should be unique. If 'path' is missing, the current folder is assumed.
!
! Copyright © 1994 by Rainbow Hill Pty Ltd. All rights reserved.
!
! ensure that the first parameter is there and that the third one is not
set doserr=13
if not "%3 " == " " goto ERR_LBL
if "%1 " == " " goto ERR_LBL
onerror ERR_LBL
! determine the folder in which the file name should be unique
set uniqueTempName_folder=%WHERE%
if "%2 " == " " goto FOLDER_OK_LBL
set doserr=27
if not existdir "%2" goto ERR_LBL
set uniqueTempName_folder=%2
:FOLDER_OK_LBL
! initialise the sequence of unique file names (all capitals so that they are visible)
set uniqueTempName_root=MACDOS-TEMP-
set uniqueTempName_seq=0
:TRYNAME_LBL
! keep trying with new names until you find one that does not exist
set uniqueTempName_name=%uniqueTempName_root%%uniqueTempName_seq%
if exist "%uniqueTempName_folder%\%uniqueTempName_name%" goto NEXTNAME_LBL
if not existdir "%uniqueTempName_folder%\%uniqueTempName_name%" goto FOUND_LBL
:NEXTNAME_LBL
incr uniqueTempName_seq
goto TRYNAME_LBL
:FOUND_LBL
! save the name into the variable specified by the caller
set %1=%uniqueTempName_name%
set doserr=0
goto DONE_LBL
:ERR_LBL
show %doserr%
:DONE_LBL
! remove the temporary variables
set uniqueTempName_name=
set uniqueTempName_root=
set uniqueTempName_seq=
set uniqueTempName_folder=